//
//  TTDiamondInfoTableViewCell.m
//  TaoTuo
//
//  Created by apple on 2020/12/11.
//  Copyright © 2020 刘广. All rights reserved.
//

#import "TTDiamondInfoTableViewCell.h"

@interface TTDiamondInfoTableViewCell ()

@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *hintLabel;
@property (nonatomic, strong) UIButton *rightBtn;

@end

@implementation TTDiamondInfoTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.backgroundColor = UIColor.clearColor;
        
        [self setupSubviews];
        
    }
    return self;
}

- (void)setModel:(TTDiamondInfoCellModel *)model
{
    _model = model;
    self.titleLabel.text = model.title;
    self.hintLabel.text = model.hintString;
    [self.rightBtn setTitle:model.rightString forState:UIControlStateDisabled];
    
    self.hintLabel.hidden = model.hiddenHint;
    
    UIColor *btnColor = model.rightTextColor ? : UIColorHex(999999);
    [self.rightBtn setTitleColor:btnColor forState:UIControlStateDisabled];
    
    // 背景
    UIRectCorner corner;
    if (model.cornerType == CornerTypeWithTop) {
        corner = UIRectCornerTopLeft | UIRectCornerTopRight;
    } else if (model.cornerType == CornerTypeWithBottom) {
        corner = UIRectCornerBottomLeft | UIRectCornerBottomRight;
    } else {
        corner = UIRectCornerAllCorners;
    }
    UIBezierPath *bgPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, SCREEN_WIDTH - 20, kDiamondInfoCellHeight) byRoundingCorners:corner cornerRadii:CGSizeMake(model.cornerRadius, model.cornerRadius)];
    CAShapeLayer *bgLayer = [CAShapeLayer layer];
    bgLayer.fillColor = UIColor.whiteColor.CGColor;
    bgLayer.path = bgPath.CGPath;
    [self.layer insertSublayer:bgLayer atIndex:0];
}

- (void)setupSubviews
{
    _titleLabel = [UILabel labelWithTitle:@"" color:UIColorHex(333333) fontSize:14];
    [self.contentView addSubview:_titleLabel];
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10);
        make.centerY.equalTo(self.contentView);
    }];
    
    _hintLabel = [UILabel labelWithTitle:@"" color:UIColorHex(999999) fontSize:12];
    [self.contentView addSubview:_hintLabel];
    [_hintLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.titleLabel.mas_right).offset(10);
        make.centerY.equalTo(self.contentView);
    }];
    
    _rightBtn = [UIButton createButtonWithTitle:@"" titleColor:UIColorHex(999999) titleFont:[UIFont systemFontOfSize:14] backgroundColor:nil target:nil action:nil];
    [_rightBtn setImage:[UIImage imageNamed:@"cellarrow_4"] forState:UIControlStateDisabled];
    [_rightBtn setSemanticContentAttribute:UISemanticContentAttributeForceRightToLeft];
    _rightBtn.enabled = NO;
    [self.contentView addSubview:_rightBtn];
    [_rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView.mas_right).offset(-10);
        make.centerY.equalTo(self.contentView);
    }];
}

@end
